package dao;

import hibernate.HibernateUtil;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import dto.ManifiestoDTO;
import entities.EmpleadoEntity;
import entities.ManifiestoEntity;

public class ManifiestoDAO {

	private static ManifiestoDAO instancia = null;
	private static SessionFactory sf = null;
	
	private ManifiestoDAO(){}
	
	public static ManifiestoDAO getInstancia(){
		if(instancia == null){
			sf = HibernateUtil.getSessionFactory();
			instancia = new ManifiestoDAO();
		} 
		return instancia;
	}

	public void grabarManifiesto(ManifiestoEntity manifiesto){
		Session session = sf.openSession();
		session.beginTransaction();
		session.persist(manifiesto);
		session.flush();
		session.getTransaction().commit();
		session.close();
	}
	
	public void actualizarManifiesto(ManifiestoEntity manifiesto){
		Session session = sf.openSession();
		session.beginTransaction();
		session.saveOrUpdate(manifiesto);
		session.flush();
		session.getTransaction().commit();
		session.close();
	}
	
	public ManifiestoEntity LoadManifiesto(int id) 
	{
		Session session = sf.openSession();
		session.beginTransaction();
		ManifiestoEntity ent = (ManifiestoEntity) session.get(ManifiestoEntity.class, id);
		session.flush();
		session.getTransaction().commit();
		session.close();
		return ent;
	}

	/*public List<ManifiestoEntity> getManifiestos() {
		// TODO Auto-generated method stub
		return null;
	}*/
}

